<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>设备管理 > 设置</title>
</head>
<body class="layui-layout-body">

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="body_right">
            <h4 class="nav_title">
            	<a href="">设备管理</a>
            	<i>></i>
                <span>设置</span>
            </h4>
            <form class="layui-form" action="">
				  <input type="hidden" name="devicesId" value="${devices.devicesId}">
				  <input type="hidden" name="sealId" value="${devices.sealId}">
				  <input type="hidden" name="workflowId" value="<#if seal??>${seal.workflowId}</#if>">
				  <input type="hidden" name="specialWorkflowId" value="<#if seal??>${seal.specialWorkflowId}</#if>">
				  <div class="layui-form-item">
		              <label for="sealName" class="layui-form-label">
		                  名称
		              </label>
		              <div class="layui-input-inline">
		                  <input type="text" id="sealName" name="sealName" value="<#if seal??>${seal.sealName}</#if>" required="" lay-verify="sealName" autocomplete="off" class="layui-input">
		              </div>
		              <div class="layui-form-mid layui-word-aux">
		                  <span class="x-red">如：财务印章</span>
		              </div>
		          </div>
		          
		          <div class="layui-form-item">
		              <label for="isForcedPhoto" class="layui-form-label">
		                  强制拍照
		              </label>
		              <div class="layui-input-inline" style="width:80px">
				        <input type="checkbox" name="isForcedPhoto" lay-filter="isForcedPhoto" value="N" <#if seal?? && seal.isForcedPhoto=="Y">checked</#if> id="isForcedPhoto"  lay-skin="switch" lay-text="是|否">
				       </div>
				       <div class="layui-form-mid layui-word-aux">
		                  <span class="x-red">启用盖章时必须拍照上传</span>
		              </div>
		          </div>
		          
		          <div class="layui-form-item">
		              <label for="model" class="layui-form-label">
		                  保管员
		              </label>
		              <div class="layui-input-inline layui-form-mid">
		              	<div id="custosPersonInfo">
		              	
		              		<#if seal??>
		              		<div class="user">
		              			<input type="hidden" name="partyId" value="${seal.partyId}">
		              			<div class="avatar"><img src="${seal.person.portrait!'/asset/images/portrait.png'}"></div>
			              		<div class="info">
			              			<div class="name">${seal.person.name}</div>
			              			<div class="position">${seal.person.position}</div>
			              		</div>
		              		</div>
		              		</#if>
		              	
		              	</div>
		              	<a href="javascript:openwinx('选择保管员','/staff/selected/index.htm?type=SELECT_CUSTOS_PERSON','1000','600');" class="layui-btn layui-btn-xs">选择保管员</a>
				      </div>
		          </div>
		          
		          <div class="layui-form-item">
		              <label for="model" class="layui-form-label">
		                  紧急申请
		              </label>
		              <div class="layui-input-inline" style="width:80px">
						<input type="text" id="limitUrgentApply" name="limitUrgentApply" value="<#if seal??>${seal.limitUrgentApply}</#if>" required="" lay-verify="limitUrgentApply" autocomplete="off" class="layui-input">				      
					 </div>
					 <div class="layui-form-mid layui-word-aux">
		                  <span class="x-red">使用失误时，可紧急申请，无需审核</span>
		              </div>
		          </div>
		          
		          <fieldset class="layui-elem-field layui-field-title">
					  <legend>审核设置</legend>
				  </fieldset>
		          
		           <div class="layui-form-item">
			            <label class="layui-form-label">审核类型</label>
			            <div class="layui-input-inline">
			                <select name="workflowType">
			                	 <option value="JOIN" <#if seal?? && seal.workflowType=='JOIN'>selected</#if> >联合审核</option>
			                     <option value="QUEUE" <#if seal?? && seal.workflowType=='QUEUE'>selected</#if>>顺序审核</option>
			                </select>
			            </div>
			        </div>
		        	<div class="layui-form-item">
		        		<label class="layui-form-label">审核人员</label>
			            <div class="layui-input-block">
			              	<input type="hidden" id="applyPersonData" value='<#if seal??>${settingsDatas}</#if>'>
			              	<ul class="new_people" id="applyPersonInfo">
			              	
				                <li id="selected">
				                	<a href="javascript:openwinx('选择审核人','/staff/selected/index.htm?type=SELECT_APPLY_PERSON','1000','600');"> 
				                    <div class="add_img bcground_999">+</div>
				                    </a>
				                </li>
				            </ul>
					    </div>
		        	</div>
		        	
		        	<div class="layui-form-item">
			              <label for="isForcedPhoto" class="layui-form-label">
			                  特批审核
			              </label>
			              <div class="layui-input-inline" style="width:80px">
					        <input type="checkbox" name="useSpecial" lay-filter="useSpecial" value="N" <#if seal?? && seal.useSpecial=="Y">checked</#if> id="useSpecial"  lay-skin="switch" lay-text="开启|关闭">
					       </div>
					       <div class="layui-form-mid layui-word-aux">
			                  <span class="x-red">特批流程为快捷备选审核流程</span>
			              </div>
			        </div>
			        <div class="layui-form-item <#if seal?? && seal.useSpecial =='N'>layui-hide</#if>" id="specialPeron">
			        	<label for="specialPeron" class="layui-form-label"></label>
					    <div class="layui-input-inline">
		              	<div id="specialPeronInfo">
		              		<#list specials as item>
		              		<div class="user">
		              			<input type="hidden" name="specialPartyId" value="${item.partyId}">
		              			<div class="avatar"><img src="${item.person.portrait!'/asset/images/portrait.png'}"></div>
		              			<div class="info">
		              				<div class="name">${item.person.name}</div>
		              			</div>
		              		</div>
		              		</#list>
		              	
		              	</div>
		              	<a href="javascript:openwinx('选择特批审核人','/staff/selected/index.htm?type=SELECT_SPECIAL_PERON','1000','600');" class="layui-btn layui-btn-xs">选择特批审核人</a>
				      </div>
			      </div>
		         
		          
		          <div class="layui-form-item">
		              <label for="L_repass" class="layui-form-label">
		              </label>
		              <button class="layui-btn layui-btn-danger" lay-filter="add" lay-submit="">提交</button>
		          </div>
				
	        	</form>
        </div>
     </div>
  
     
     <script>
     
        //JavaScript代码区域
        layui.use(['element','form','layedit','laypage'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            
            
            form.verify({
			  sealName: function(value, item){ //value：表单的值、item：表单的DOM对象
			    
			    if(!value){
			      return '印章名称不能为空';
			    }
			  },
			  partyId: function(value, item){ //value：表单的值、item：表单的DOM对象
			    
			    if(!value){
			      return '请选择保管员';
			    }
			  }
			});      
            
            
            form.on('switch(isForcedPhoto)', function(data){
            
            		if(data.elem.checked){
            			$(this).val("Y")
            		}else{
            			$(this).val("N")
            		}
			}); 
			
			  
            form.on('switch(useSpecial)', function(data){
            
            		if(data.elem.checked){
            			$("#specialPeron").removeClass("layui-hide");
            		}else{
            			$("#specialPeron").addClass("layui-hide");
            		}
			});  
          	
          //监听提交
            form.on('submit(add)', function(data){
            		var field = data.field;
            		
            		//审核人相关
            		var applyPersonData = $('#applyPersonData').val();
			        if(!applyPersonData){
			        	layer.msg("请设置审核人");
			        	return false;
			        }
			        
			        var dataList = eval('(' + applyPersonData + ')'),verifyPartyIds="";
			        for(i=0;i<dataList.length;i++){
			        	if(i > 0 ){
		            		verifyPartyIds+=","
		            	}
			        	verifyPartyIds += dataList[i].id+"|"+(i+1);
			        	console.log(verifyPartyIds);
			        
			        }
	            	
	            	field.verifyPartyIds = verifyPartyIds;
	            	
	            	
	            	if($("#useSpecial").is(':checked')){
	            		if(!field.specialPartyId){
		            		layer.msg("请设置特批流程审核人");
				        	return false;
	            		}
	            	}
	            	
            		
            		
            		
            		console.log(field);
            	   $.ajax({
					type:"POST", 
					url:"/devices/setting/post.htm",
					data:field,
					success:function(result) {
						if(result.code=='1'){
							layer.alert("设置成功", {icon: 6},function () {
				            		location.href="/devices/list.htm";
				       		});
						}else{
						 	layer.msg(result.msg);
						}
				 	} 
				});
           
                return false;
            });
        });
    </script>   
    
    
    <script>
    
   		 var nubList = new Array(), $applyPersonData = $("#applyPersonData");
        
        
        function leftMove(index){
        	var a = nubList[index];
        	nubList[index] = nubList[index-1]
        	nubList[index-1] =a;
        	$applyPersonData.val(JSON.stringify(nubList))
        	info();
        	
        }
        
        function rigthMove(index){
        	var a = nubList[index];
        	nubList[index] = nubList[index+1]
        	nubList[index+1] =a;
        	$applyPersonData.val(JSON.stringify(nubList))
        	info();
        }
        
        function del(index){
        	nubList.splice(index, 1);
        	$applyPersonData.val(JSON.stringify(nubList))
        	info();
        }
        
        function info(){
        	var applyPersonData = $applyPersonData.val();
        	console.log(applyPersonData);
	        if(applyPersonData){
	        	nubList = eval('(' + applyPersonData + ')');
	        }
        	
        	var items = new Array();
        	
        	if(nubList.length==1){
	        	items=items.concat(
	        		['<li class="person">',
	                    '<div class="header_top">',
	                        '<img src="'+nubList[0].portrait+'" alt="" class="vatol_img">',
	                    '</div>',
	                    '<p class="only_title">'+nubList[0].name+'</p>',
	                    '<i class="icon_close" onclick="del(0)">x</i>',
	                '</li>'
			        ]
			     )
        	}else if(nubList.length > 1){
        		for(var i=0;i<nubList.length;i++){
        			if(i==0){
        				items=items.concat(
			        		['<li class="person">',
			                    '<div class="header_top">',
			                        '<img src="'+nubList[i].portrait+'" alt="" class="vatol_img">',
			                        '<div class="row">',
			                            '<a href="javascript:rigthMove('+i+')">></a>',
			                        '</div>',
			                    '</div>',
			                    '<p class="only_title">'+nubList[i].name+'</p>',
			                    '<i class="icon_close" onclick="del('+i+')">x</i>',
			                '</li>'
					        ]
					     )
        			}else if(nubList.length-1 == i){
        				items=items.concat(
			        		['<li class="person">',
			                    '<div class="header_top">',
			                        '<img src="'+nubList[i].portrait+'" alt="" class="vatol_img">',
			                        '<div class="row">',
			                            '<a href="javascript:leftMove('+i+')"><</a>',
			                        '</div>',
			                    '</div>',
			                    '<p class="only_title">'+nubList[i].name+'</p>',
			                    '<i class="icon_close" onclick="del('+i+')">x</i>',
			                '</li>'
					        ]
					     )
        			
        			}else{
        				var portrait = nubList[i].portrait?nubList[i].portrait:'/asset/images/portrait.png';
        				items=items.concat(
			        		['<li class="person">',
			                    '<div class="header_top">',
			                        '<img src="'+portrait+'" alt="" class="vatol_img">',
			                        '<div class="row">',
			                            '<a href="javascript:leftMove('+i+')"><</a>&nbsp&nbsp <a href="javascript:rigthMove('+i+')">></a>',
			                        '</div>',
			                    '</div>',
			                    '<p class="only_title">'+nubList[i].name+'</p>',
			                    '<i class="icon_close" onclick="del('+i+')">x</i>',
			                '</li>'
					        ]
					     )
        			
        			}
        		
        		}
        	}
			$("#selected").prevAll().remove();
			$(items.join('')).insertBefore("#selected");
			
			
        }
    	info();
    
    </script>
     
</body>
</html>